// ======================================================
//     Copyright (c) 2009 METARACE  All rights reserved.
//    
//     The use and distribution terms for this software are contained in the file
//     named license.txt, which can be found in the root of this distribution.
//     By using this software in any fashion, you are agreeing to be bound by the
//     terms of this license.
//    
//     You must not remove this notice, or any other, from this software.
// ======================================================
using log4net;

namespace Toulr.Util.Logging.log4netIntegration
{
    #region

    

    #endregion

    public class ExtendedLog4netLogger : Log4NetLogger, IExtendedLogger
    {
        private static readonly IContextProperties globalContextProperties = new GlobalContextProperties();
        private static readonly IContextProperties threadContextProperties = new ThreadContextProperties();
        private static readonly IContextStacks threadContextStacks = new ThreadContextStacks();

        public ExtendedLog4netLogger(ILog log, ExtendedLog4NetFactory factory) : this(log.Logger, factory)
        {
        }

        public ExtendedLog4netLogger(log4net.Core.ILogger logger, ExtendedLog4NetFactory factory)
        {
            Logger = logger;
            Factory = factory;
        }

        protected internal new ExtendedLog4NetFactory Factory { get; set; }

        #region IExtendedLogger Members

        /// <summary>
        /// Exposes the Global Context of the extended logger. 
        /// </summary>
        public IContextProperties GlobalProperties
        {
            get { return globalContextProperties; }
        }

        /// <summary>
        /// Exposes the Thread Context of the extended logger.
        /// </summary>
        public IContextProperties ThreadProperties
        {
            get { return threadContextProperties; }
        }

        /// <summary>
        /// Exposes the Thread Stack of the extended logger.
        /// </summary>
        public IContextStacks ThreadStacks
        {
            get { return threadContextStacks; }
        }

        #endregion

        public IExtendedLogger CreateExtendedChildLogger(string name)
        {
            return Factory.Create(Logger.Name + "." + name);
        }
    }
}